package com.yang;

public class AddOneThread extends Thread {
    private boolean isStart = true;
    private boolean enable = true;
    private int count = 0;

    @Override
    public void run() {
        while(isStart) {
            try {
                if(enable) {
                    this.count = (this.count + 1) % 100;
                }
                sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }


    public void pauseAddOne() {
        this.enable = false;
    }

    public void continueAddOne() {
        this.enable = true;
    }

    public void endThread() {
        this.isStart = false;
    }

    public int getCount() {
        return this.count;
    }
}